package org.csu.mybigpro.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.csu.mybigpro.common.CommonResponse;
import org.csu.mybigpro.domain.OperationLog;
import org.csu.mybigpro.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/audit")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    @GetMapping("/logs")
    public CommonResponse<Page<OperationLog>> getLogs(
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        Page<OperationLog> logPage = operationLogService.getLogsByCondition(username, type, startDate, endDate, page, size);
        return CommonResponse.createForSuccess(logPage);
    }
}
